local Lua__yiqi = fk.CreateSkill {
    name = "Lua__yiqi",
    anim_type = "offensive",
    tags = {Skill.Charge},
  }
  
  Fk:loadTranslationTable{
    ["Lua__yiqi"] = "义气",
    [":Lua__yiqi"] = "蓄力技（1/5），当你造成或受到伤害后，获得一个蓄力点。出牌阶段限一次，你可以将一张手牌交给一名其他角色，然后你选择一项：1.获得三个蓄力点；2.摸三张牌。当你受到伤害时，你可消耗一个蓄力点，防止此伤害",
    ["#Lua__yiqi-invoke"] = "义气：你可消耗1蓄力点防止此伤害。",
    ["Lua__yiqi1"] = "获得三个蓄力点",
    ["Lua__yiqi2"] = "摸三张牌",
    ["#Lua__yiqi"] = "义气：你可以将一张手牌交给一名其他角色，然后你选择一项。",

  }

local U = require "packages.utility.utility"

Lua__yiqi:addEffect(fk.Damage, {
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(Lua__yiqi.name) and target == player 
    end,
    on_use = function(self, event, target, player, data)
        U.skillCharged(player, 1)
    end,
})

Lua__yiqi:addEffect(fk.Damaged, {
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(Lua__yiqi.name) and target == player 
    end,
    on_use = function(self, event, target, player, data)
        U.skillCharged(player, 1)
    end,
})

Lua__yiqi:addEffect(fk.DamageInflicted, {
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(Lua__yiqi.name) and target == player and player:getMark("skill_charge") > 0
    end,
    on_cost = function(self, event, target, player, data)
        return player.room:askToSkillInvoke(player,{
         skill_name= Lua__yiqi.name,
         data=data,
         prompt="#Lua__yiqi-invoke"
       })
     end,
    on_use = function(self, event, target, player, data)
        U.skillCharged(player, -1)
        data:preventDamage()
    end,
})


Lua__yiqi:addEffect("active", {
    anim_type = "control",
    prompt = "#Lua__yiqi",
    card_num = 1,
    target_num = 1,
    can_use = function(self, player)
      return player:usedSkillTimes(Lua__yiqi.name, Player.HistoryPhase) == 0
    end,
    interaction = function(self, player)
        local choices = {"Lua__yiqi2"}
        if player:getMark("skill_charge") ~= 5 then
            table.insert(choices,"Lua__yiqi1")
        end
        return UI.ComboBox {choices = choices}
      end,
    card_filter = function(self, player, to_select, selected)
      return #selected == 0 and table.contains(player:getCardIds("h"), to_select)
    end,
    target_filter = function(self, player, to_select, selected, cards)
      return #selected == 0 and to_select ~= player 
    end,
    on_use = function(self, room, effect)
        local player = effect.from
        local to = effect.tos[1]
        room:moveCardTo(effect.cards, Player.Hand, to, fk.ReasonGive, Lua__yiqi.name, nil, false, player)
        if self.interaction.data == "Lua__yiqi1" then
            U.skillCharged(player, 3)
        else
            room:drawCards(player,3)
        end
      
    end,
  })




Lua__yiqi:addLoseEffect(function(self, player)
      U.skillCharged(player, -1, -5)
end)

Lua__yiqi:addAcquireEffect(function(self, player)
    U.skillCharged(player, 1, 5)
end)


  
  return Lua__yiqi